package com.jztd.servone.invoice.po;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import cn.xbatis.db.annotations.Table;
import com.jztd.servone.invoice.param.OrderInterfaceConfigParam;
import lombok.Data;

import java.util.List;

@Data
@Table
public class BusinessConfig {
    private int id;
    private String type;
    private String name;
    private String code;
    private String url;
    private String method;
    private String pathParam;
    private String bodyParam;
    private String partyConfigCode;
    private String createTime;
    private String updateTime;
    private String createBy;
    private String updateBy;
    private String deleted;

    public OrderInterfaceConfigParam getOrdeDetailsrUrl() {
        if (ObjectUtil.isNotEmpty(method)) {
            List<OrderInterfaceConfigParam> orderParamList = Convert.toList(OrderInterfaceConfigParam.class, JSONUtil.parseArray(this.method));
            for (OrderInterfaceConfigParam orderParam : orderParamList) {
                if (orderParam.getType().equals("details")) {
                    return orderParam;
                }
            }
        }
        return null;

    }

    public OrderInterfaceConfigParam getOrdeListUrl() {
        if (ObjectUtil.isNotEmpty(method)) {
            List<OrderInterfaceConfigParam> orderParamList = Convert.toList(OrderInterfaceConfigParam.class, JSONUtil.parseArray(this.method));
            for (OrderInterfaceConfigParam orderParam : orderParamList) {
                if (orderParam.getType().equals("list")) {
                    return orderParam;
                }
            }
        }
        return null;
    }
}
